#ifndef XVIDEOTHREAD_H
#define XVIDEOTHREAD_H

#include <QThread>
#include <QMutex>
#include <opencv.hpp>

using namespace cv;
class XVideoThread : public QThread
{
    Q_OBJECT
public:

    int fps = 0;
    int width = 0;
    int height = 0;
    int width2 = 0;
    int height2 = 0;
    int totalMs = 0;

    std::string srcFile;
    std::string desFile;


    int begin = 0;
    int end = 0;

    void SetBegin(double p);
    void SetEnd(double p);

    static XVideoThread * Get()
    {
        static XVideoThread vt;
        return &vt;
    }
    bool  Open(const std::string file);
    bool  Open2(const std::string file);

    //进度条
    double GetPos();
    //跳转视频
    bool Seek(int frame);
    bool Seek(double pos);
    //保存视频
    bool StartSave(const std::string filename,int width=0,int height =0,bool isColor =false);

    //停止
    void StopSave();

    void play();
    void stop();

    //添加水印
    void SetMark(Mat mark);

    ~XVideoThread();

    void run();
signals:
    void ViewImage1(Mat mat);
    void ViewImage2(Mat mat);
    void ViewDes(Mat mat);

    void SaveEnd();
private:
    QMutex mutex;

    //是否开始写视频
    bool isWrite = false;
    bool isPlay = false;
    bool isExit =true;

    Mat mark;
    XVideoThread();
};

#endif // XVIDEOTHREAD_H
